// pages/guide/index.js
Page({
  data: {
    guides: [
      {
        id: 1,
        title: "成都春熙路美食攻略",
        cover: "/assets/img/message/精品推荐6.jpg",
        author: "美食达人",
        views: 1234,
        likes: 89,
        tags: ["美食", "春熙路", "成都"],
        content: "春熙路是成都最繁华的商业街，这里汇聚了各种美食...",
        publishTime: "2024-01-15 10:30"
      },
      {
        id: 2,
        title: "周末徒步路线推荐",
        cover: "/assets/img/message/精品推荐4.jpg",
        author: "户外爱好者",
        views: 856,
        likes: 67,
        tags: ["徒步", "周末", "户外"],
        content: "推荐几条适合周末徒步的路线，风景优美，难度适中...",
        publishTime: "2024-01-14 16:20"
      },
      {
        id: 3,
        title: "城市夜景拍摄地点",
        cover: "/assets/img/message/精品推荐3.jpg",
        author: "摄影爱好者",
        views: 2341,
        likes: 156,
        tags: ["摄影", "夜景", "打卡"],
        content: "分享几个绝佳的城市夜景拍摄地点，出片率很高...",
        publishTime: "2024-01-13 20:15"
      },
      {
        id: 4,
        title: "本地特色小店推荐",
        cover: "/assets/img/message/精品推荐2.jpg",
        author: "本地通",
        views: 987,
        likes: 78,
        tags: ["小店", "特色", "推荐"],
        content: "发现了几家很有特色的本地小店，值得一去...",
        publishTime: "2024-01-12 14:45"
      }
    ],
    categories: [
      { name: "全部", active: true },
      { name: "美食", active: false },
      { name: "景点", active: false },
      { name: "购物", active: false },
      { name: "交通", active: false }
    ]
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '本地攻略'
    })
  },

  onGuideTap: function(e) {
    const guide = e.currentTarget.dataset.guide
    
    wx.showModal({
      title: guide.title,
      content: `作者：${guide.author}\n浏览量：${guide.views}\n点赞：${guide.likes}\n发布时间：${guide.publishTime}\n\n${guide.content}`,
      showCancel: true,
      cancelText: '关闭',
      confirmText: '查看详情',
      success: function(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: `/pages/guide-detail/index?id=${guide.id}`
          })
        }
      }
    })
  },

  onCategoryTap: function(e) {
    const index = e.currentTarget.dataset.index
    const categories = this.data.categories.map((item, i) => {
      item.active = i === index
      return item
    })
    this.setData({ categories })
    
    wx.showToast({
      title: '筛选：' + categories[index].name,
      icon: 'none'
    })
  },

  onSearchInput: function(e) {
    const value = e.detail.value
    if (value.trim()) {
      wx.showToast({
        title: '搜索：' + value,
        icon: 'none'
      })
    }
  }
})
